package org.wycash.object;

public class Money implements Expression{

	public int amount;
	private String currency;

	public Money(int amount, String currency) {
		this.amount = amount;
		this.currency = currency;
	}

	@Override
	public boolean equals(Object obj) {
		Money money = (Money) obj;
		return money.amount == amount && currency.equals(money.currency());
	}

	public String currency() {
		return currency;
	}
	
	public Expression times(int multiplier) {
		return new Money(amount*multiplier,currency);
	}
	
	public static Money dollar(int amount) {
		return new Money(amount,"USD");
	}

	public static Money franc(int amount) {
		return new Money(amount,"CHF");
	}

	@Override
	public Expression plus(Expression addend) {
		return new Sum(this,addend);
	}
	
	public Money reduce(Bank bank, String to){
		int rate = bank.rate(currency, to);
		return new Money(amount/rate, to);
	}
}